package com.hzeport.bgs22emduty.inbound.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzeport.bgs22emduty.config.SystemConfig;
import com.hzeport.bgs22emduty.config.login.LoginCompoentService;
import com.hzeport.bgs22emduty.config.login.UserInfoDetailVO;
import com.hzeport.bgs22emduty.dto.ParamVo;
import com.hzeport.bgs22emduty.service.ParamGroupDutyService;
import com.hzeport.bgs22emduty.vo.base.PageVO;
import com.hzeport.bgs22emduty.vo.paramgroupduty.ParamGroupDutyListVo;
import com.hzeport.bgs22emduty.vo.paramgroupduty.ParamGroupDutyDto;
import com.hzeport.bgs22emduty.common.base.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author hzeport
 */

@RestController
@AllArgsConstructor
@RequestMapping( "/paramgroupduty")
@Api( value = "paramgroupduty", tags = "群组设置")
@Slf4j
public class ParamGroupDutyController {

    private final ParamGroupDutyService paramGroupDutyService;

    private final LoginCompoentService loginCompoentService;

    private final SystemConfig systemConfig;

    @ApiOperation( value = "分页列表" )
    @RequestMapping( value = "getPage", method = RequestMethod.POST )
    public BaseResult< Page< ParamGroupDutyListVo > > getPage( @RequestBody PageVO pageVO ) {
        UserInfoDetailVO userInfoDetailVO = loginCompoentService.getUserInfo();
        return paramGroupDutyService.getPage( pageVO , userInfoDetailVO );
    }

    @ApiOperation( value = "保存" )
    @RequestMapping( value = "saveData", method = RequestMethod.POST )
    public BaseResult< String > saveData( @RequestBody @Validated ParamGroupDutyDto dto ) {
        UserInfoDetailVO userInfoDetailVO = loginCompoentService.getUserInfo();
        return paramGroupDutyService.saveData( dto , userInfoDetailVO );
    }

    @ApiOperation( value = "删除" )
    @RequestMapping( value = "delete", method = RequestMethod.POST )
    public BaseResult< String > delete( @RequestBody  ParamGroupDutyDto dto ) {
        UserInfoDetailVO userInfoDetailVO = loginCompoentService.getUserInfo();
        return paramGroupDutyService.delete( dto , userInfoDetailVO );
    }

    @ApiOperation( value = "群组列表" )
    @RequestMapping( value = "getGroupList", method = RequestMethod.GET )
    public BaseResult< List< ParamVo > > getGroupList( ) {
        UserInfoDetailVO userInfoDetailVO = loginCompoentService.getUserInfo();
        return paramGroupDutyService.getGroupList(userInfoDetailVO);
    }

    @ApiOperation( value = "H4A群组链接" )
    @RequestMapping( value = "getGroupUrl", method = RequestMethod.GET )
    public BaseResult< String > getGroupUrl() {
        return BaseResult.ok( systemConfig.getH4aGroupUrl() );
    }

    @ApiOperation( value = "根据群组获取人员" )
    @RequestMapping( value = "getGroupUser", method = RequestMethod.GET )
    public BaseResult< List< ParamVo > > getGroupUser( @RequestParam("groupId") String groupId ) {
        return paramGroupDutyService.getGroupUser( groupId );
    }


}
